package com.yyy.gui.listener;

import com.yyy.gui.pannel.ConfigPanel;
import com.yyy.service.ConfigService;
import com.yyy.util.GUIUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 * @Author：yyy
 * @Package：com.yyy.gui.listener
 * @Project：HuTuBiill
 * @name：ConfigListener
 * @Date：2024/11/12 22:14
 * @Filename：ConfigListener
 */
public class ConfigListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        ConfigPanel p=ConfigPanel.instance;

        if(!GUIUtil.checkNumber(p.tfBudget,"本月预算"))
            return;
        String mysqlPath=p.tfMysqlPath.getText().trim();
        if(mysqlPath.length()!=0){
            File commandFile=new File(mysqlPath,"bin/mysql.exe");//判断mysql安装路径是否存在mysql.exe文件
            if(!commandFile.exists()){
                JOptionPane.showMessageDialog(p,"Mysql路径不正确");
                p.tfMysqlPath.grabFocus();
                return;
            }
        }
        ConfigService cs=new ConfigService();
        cs.update(ConfigService.budget,p.tfBudget.getText().trim());
        cs.update(ConfigService.mysqlpath,p.tfBudget.getText().trim());
        JOptionPane.showMessageDialog(p,"设置修改成功");

    }
}
